﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chbl.DataAccess.DTO;
using Chbl.DataAccess.Repositories;

namespace Chbl.Controllers
{    
    public class FileController : Controller
    {
        private readonly IGalleryServerProRepository _galleryServerProRepository;
        private readonly string _pathFormat = ConfigurationManager.AppSettings["GPSFilePathFormat"];
        private const string _contentType = "application/octet-stream";

        public FileController(IGalleryServerProRepository galleryServerProRepository)
        {
            _galleryServerProRepository = galleryServerProRepository;
        }

        public FilePathResult DownloadMediaObject(int id)
        {
            MediaObject mediaObject = _galleryServerProRepository.GetMediaObject(id);
            var result = new FilePathResult(
                Url.Content(string.Format(_pathFormat, mediaObject.DirectoryName, mediaObject.FileName)), _contentType)
                             {FileDownloadName = mediaObject.FileName};
            return result;            
        }
    }
}
